#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

bool is_prime(int num) {
    if(num < 2) {
        return false;
    }
    for(int i = 2; i * i <= num; i++) {
        if(num % i == 0) {
            return false;
        }
    }
    return true;
}

int get_nearest_prime(int num) {
    int lower_num = num;
    int upper_num = num;

    while (!is_prime(lower_num) && !is_prime(upper_num)) {
        lower_num--;
        upper_num++;
    }

    while (!is_prime(lower_num)) {
        lower_num--;
    }

    while (!is_prime(upper_num)) {
        upper_num++;
    }

    return min(lower_num, upper_num);
}

int main() {
    unordered_map<string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    string word1, word2, word3;
    cin >> word1 >> word2 >> word3;

    if(numbers.find(word1) == numbers.end() || numbers.find(word2) == numbers.end() || numbers.find(word3) == numbers.end()) {
        cout << "Wrong input" << endl;
        return 1;
    }

    int num = numbers[word1] * 100 + numbers[word2] * 10 + numbers[word3];

    if (num < 100 || num > 999) {
        cout << "Wrong input" << endl;
    } else {
        int result = get_nearest_prime(num);
        cout << result << endl;
    }

    return 0;
}
